package feizhou.untils.temp.strReplace;

import feizhou.untils.tools.http.HttpUtils;
import feizhou.untils.tools.io.IOStreamUtil;
import feizhou.untils.tools.PropertyUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.Set;


/**
 * @ClassName: DMPUtil
 * @Description 文本内容处理
 * @Author feizhou
 * @Date 2023/8/15  15:50
 * @Verson 1.0
 **/
public class FileContextUtil {
    static Logger logger = LoggerFactory.getLogger(HttpUtils.class);


    public static void stringReplace() {
        String fileDir = "D:\\java\\workSpace-learn\\周飞开发的通用工具\\java_util\\src\\main\\java\\feizhou\\untils\\temp\\strReplace\\file\\";
        String file_rule = "rule.properties";
        String file_input = "input.txt";
        String file_output = "output.txt";

        Properties properties = PropertyUtil.getProperties(fileDir + file_rule);

        Set<Object> rules = (Set<Object>) properties.keySet();


        List<String> lines = IOStreamUtil.read_bufferedReader(fileDir + file_input);
        List<String> newLines = new ArrayList<>();


        lines.forEach(line -> {
            for (Object key : rules) {
                String keyStr = (String) key;
                line = line.replaceAll(keyStr, properties.getProperty(keyStr));
            }
            newLines.add(line);
        });

        IOStreamUtil.write_bufferedWriter(newLines, fileDir + file_output);

    }


    public static void main(String[] args) throws Exception {
        stringReplace();

    }
}